﻿// JScript 文件
var  vCfgStatus = null
var  vPzType    = null  
var  vSf        = null
var  preSf      = ""
var  vOldBm     = ""
var  vNewBm     = ""
var  IsSelGr    = null
var  TicketNo   = null 
var  vGrtype    = null
var  DzType     = null
var  Res        = null
var  vTask      = ""
var  OldBmList  = new Array();
var  NewBmList  = new Array();


function TicketCfg()
{
    this.Xlh = null;                      //序列号       
    this.State = null;                    //订单状态
    this.YwDz = null;                     //业务动作
    this.Task = null;                     //任务项 
    this.CfgStatus = null;                //订单配置状态
}
function GrCfgPamas()
{
    this.DzType       = null;                 //订单业务动作类型
    this.SerialNo     = null;                 //序列号
    this.IsSF         = null;                 //是否SF
    this.GluBm        = null;                 //光路编码
    this.GrPzType     = null;                 //光路配置类型
    this.newBm        = null;                 //
    this.GrType       = null;                 //光路类型
    this.TicketNo     = null;                 //订单编号
    this.Task         = null;                 //任务项
    this.BjoperCode   = null;                 //报竣操作
}

var CfgPamas = new GrCfgPamas()

function GeSet()
{
    Res = GetSysCfg()
    vGrtype = Res.GRTYPE
    vSf = TickerPamas.Xlh
    DzType = getOper(TickerPamas.YwDz)
    if(Res.CFGTYPE == 2)
    {
        vCfgStatus = 0
    }
    else
    {
        vTask = TickerPamas.Task
        if(preSf != vSf)
           vCfgStatus = null
        getStatus()
        preSf = vSf
    }
    var vUrl = "/main.ashx?_method=initCfgParms&State="+escape(vCfgStatus)+"&xlh="+escape(vSf)+"&actionType="+escape(DzType)
    var vData = CtnTrans.getText(vUrl);
    if (!CtnError.validate(vData))
    {
        CtnError.show()
        if(vCfgStatus == 1)
        {
           if(confirm("是否光路重配?"))
           {
               vOper = "0"
               vOldBm = "";
               vNewBm = "";
               tmpGrtype = "2";
               vPzType = "0";
               CfgPamas = new GrCfgPamas();
               CfgPamas.DzType = DzType;
               CfgPamas.SerialNo = vSf;
               CfgPamas.Task = vTask;
               CfgPamas.IsSF = 1;
               CfgPamas.GluBm = vOldBm;
               CfgPamas.GrPzType = vPzType;
               CfgPamas.GrType = tmpGrtype;
               CfgPamas.newBm = vNewBm

               top.ExecuteATool(top.m_vt.GQGRGL_GRCFG, [CfgPamas])
           }
        } 
        return;
    }
    else
    {
        while(OldBmList.length > 0)
        {
            OldBmList.pop();
        }
        while(NewBmList.length > 0)
        {
            NewBmList.pop();
        }
        var XmlVal = GetXmlDoc(vData)
        var nodes = XmlVal.selectNodes('Items/Item');
        var Cfgnodes = nodes[0].selectNodes('CfgParms')
        vPzType = $XML(Cfgnodes[0],"GrPzType")
        vOldBm = $XML(Cfgnodes[0],"OldGrBm")
        vNewBm = $XML(Cfgnodes[0],"newGrBm")
        IsSelGr = $XML(Cfgnodes[0],"isSelGr")
        var strOldBm = $XML(Cfgnodes[0],"OldBmlist")
        var strNewBm = $XML(Cfgnodes[0],"NewBmlist")
        if(strOldBm != null)
        {
            OldBmList = strOldBm.split('|');
            NewBmList = strNewBm.split('|');
        }
        GrCfgs()
    }
}
function GrCfgs()
{
    if(IsSelGr == "true")
    {
        top.ExecuteATool(top.m_vt.KJZYGL_QUERYINFO, [CtnMajorDef.TEL_MAJ_ATT, CtnMinorDef.TEL_ATT_GR, PutResult11])
        return;
    }
    
    if(OldBmList.length == 1)//已配置过的
    {
       if(OldBmList[0].length > 0)
       {
           vOldBm = OldBmList[0]
           vNewBm = NewBmList[0]
       }    
    }
   else if(OldBmList.length > 1)
   {
        ///选择一条
        SelaGr(OldBmList,NewBmList)
        return
   }
   
    var tmpGrtype = ""
    if(vPzType == "0")
       tmpGrtype = "2"
    else if(vOldBm.indexOf("E") == 0)
       tmpGrtype = "1"  
    else
       tmpGrtype = "0"  
       
    CfgPamas = new GrCfgPamas();
    CfgPamas.DzType = DzType;
    CfgPamas.SerialNo = vSf;
    CfgPamas.IsSF = 1;
    CfgPamas.GluBm = vOldBm;
    CfgPamas.GrPzType = vPzType;
    CfgPamas.GrType = tmpGrtype;
    CfgPamas.newBm = vNewBm
    
    if(parseInt(Res.CFGTYPE) == 2)
    {
        CfgPamas.TicketNo = TicketNo;
    }  
    else
    { 
        if(GrReCfg())
        {
            cfgRes()
            return;
        }
        CfgPamas.Task = vTask;
    }          
    top.ExecuteATool(top.m_vt.GQGRGL_GRCFG, [CfgPamas])
}
function PutResult11(dlg)
{
    var strcolone = "bm";
    var colone = dlg.wnd.getSelItem(strcolone)
    if(colone == "")
    {
        CtnDlg.msg("请选择光路！")
        return;
    }
    var vTmpXmlDocone = CtnXML.getXmlDoc()
    vTmpXmlDocone.loadXML(colone)
    
    var vBmNode = vTmpXmlDocone.selectNodes("item/"+strcolone)
    var GrBm = $XML(vBmNode[0])
    vOldBm = GrBm
    if(GrBm.indexOf("E") == 0)
    {
        vGrtype = "1"  
    }
    else
    {
        vGrtype = "0"
    }
    dlg.close();
    GrOper()
}
function GrOper()
{
    var vUrl = "/main.ashx?_method=GrOper&operType="+escape(DzType)+"&xlh="+escape(vSf)+"&GrBm="+escape(vOldBm)+"&GrType="+escape(vGrtype)+ "&TicketNo=" + TicketNo+"&CFGTYPE="+Res.CFGTYPE; 
    var vData = CtnTrans.getText(vUrl);
    if (!CtnError.validate(vData))
    {
        CtnError.show()
        return;
    }
    else
    {
        var XmlVal = GetXmlDoc(vData)
        var nodes = XmlVal.selectNodes('Items/Item');
        var Resultnodes = nodes[0].selectNodes('Result')
        var Tmpval = $XML(Resultnodes[0],"val")
        GetOperResult(Tmpval)
    }
}
function GetOperResult(Tmpval)
{
     if("" == Tmpval || Tmpval == undefined)
     {
         CtnDlg.msg("光路操作失败！") 
         return
     }   
     if("DelSucess" == Tmpval)
     {
         if(parseInt(Res.CFGTYPE) == 2)
         {  
//             Query(0)
             CtnDlg.confirm("拆除光路成功? 是否输出工单！", DelFun)
             
         }   
         else
         {
             CtnDlg.msg("拆除光路成功！")
//             Query(0)
         }   
         return   
     }
     if("Sucess" != Tmpval)
     {
         CtnDlg.msg(Tmpval)
         return   
     }    
     
     CfgPamas = new GrCfgPamas()
     CfgPamas.DzType = DzType;
     CfgPamas.SerialNo = vSf;
     CfgPamas.IsSF = 1;
     CfgPamas.GluBm = vOldBm;
     CfgPamas.GrPzType = vPzType;
     CfgPamas.GrType = vGrtype;
        
     //调整
     if(parseInt(Res.CFGTYPE) == 2)
     {
         CfgPamas.TicketNo = TicketNo;
     }
     else
     {
         CfgPamas.Task = vTask;
     }
     top.ExecuteATool(top.m_vt.GQGRGL_GRCFG, [CfgPamas])
}
function SelaGr(oldBmlist,newBmlist)
{
    
}
function DelFun(bflg)
{
    if(bflg)
    {
//        var Url = "Gqgr/TicketPrint.aspx?GrBm=" + escape(vOldBm)
//            + "&GrType=" + escape(vGrType)
//            + "&TransferCfg=0";
//        top.ExcuteATool(top.m_vt.ID_TICKETPRINT, Url) 
    }
}
var returnVal = false
function GrReCfg()
{
   if(vCfgStatus == 1)
   {
       CtnDlg.confirm("是否光路重配?", ReCfgGr)
   } 
}
function ReCfgGr(bflg)
{
    if(bflg)
    {
        returnVal = true;
    }
}
function cfgRes()
{
    var vUrl = "/main.ashx?_method=DelGrByXlh&XLH=" + vSf + "&GRBM=" + vOldBm;
    var vData = CtnTrans.getText(vUrl);
    if (!CtnError.validate(vData))
    {
        CtnError.show()
        return;
    }
    else
    {
        var XmlVal = GetXmlDoc(vData)
        var nodes = XmlVal.selectNodes('Items/Item');
        var Resultnodes = nodes[0].selectNodes('Result')
        var Tmpval = $XML(Resultnodes[0],"val")
        var vData = $XML(Resultnodes[0],"Data")
        if(val == "FAIL")
        {
            CtnDlg.msg(vData)
        }
        else
        {
            vOper = "0"
            vOldBm = "";
            vNewBm = "";
            tmpGrtype = "2";
            vPzType = "0";
            
            CfgPamas = new GrCfgPamas();
            CfgPamas.DzType = DzType;
            CfgPamas.SerialNo = vSf;
            CfgPamas.Task = vTask;
            CfgPamas.IsSF = 1;
            CfgPamas.GluBm = vOldBm;
            CfgPamas.GrPzType = vPzType;
            CfgPamas.GrType = tmpGrtype;
            CfgPamas.newBm = vNewBm

            top.ExecuteATool(top.m_vt.GQGRGL_GRCFG, [CfgPamas])
        }
    }
}
function GetXmlDoc(vData)
{
     var XmlDoc = CtnXML.getXmlDoc();
     if (vData.indexOf("<?xml") == -1)
     {
         vData = "<?xml version='1.0' encoding='gb2312' ?><Items>" + vData + "</Items>";
     }
     try
     {
         XmlDoc.loadXML(vData);
     }
     catch (e)
     {
         CtnDlg.msg("xml数据不符合规范！");
         return false;
     }
     return XmlDoc
}
function getOper(vOper)
{
    switch(vOper)
    {
       case "新装":
       case "装":
         vOper = "0"
         break;
       case "割接":
       case "移机":
       case "改":
         vOper = "1"
         break;
       case "拆机":
       case "拆":
         vOper = "2"
         break;     
       default:
         break;
    }
    return vOper
}

function getStatus()
{
   if(vCfgStatus == null)
   { 
       vCfgStatus = TickerPamas.CfgStatus               //订单配置状态
       switch(vCfgStatus)
       {
           case "未配置":
              vCfgStatus = 0; 
              break;
           default:
              vCfgStatus = 1; 
              break;
       }
   }
}